<?php
    // the upload function
 
    if(is_uploaded_file($_FILES['datafile']['tmp_name'])) {
		
        // prepare the image for insertion
        $imgData = addslashes (file_get_contents($_FILES['datafile']['tmp_name']));
 
        // get the image info..
		$type = substr($_FILES['datafile']['type'], 6);
		$size = $_FILES['datafile']['size'];
		$name = $_FILES['datafile']['name'];
 
        // put the image in the db...
		// database connection
		mysql_connect("localhost", "root", "643313") OR DIE (mysql_error());

		// select the db
		mysql_select_db ("test") OR DIE ("Unable to select db".mysql_error());
 
        // our sql query
        $sql = "INSERT INTO images
                VALUES
                ('0', '$type', '$imgData', '$size', '$name')";
		echo $sql;
        // insert the image
        if(!mysql_query($sql)) {
            echo 'Unable to upload file';
        }
    }
    else {
		// if the file is not less than the maximum allowed, print an error
		echo
		'<div>File exceeds the Maximum File limit</div>
		<div>Maximum File limit is '.$maxsize.'</div>
		<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div>
		<hr />';
	}
?>